package spring.cloud.tasks.executor.executor.task.execute_statistics;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.common.nodepaths.TaskNodePaths;
import spring.cloud.tasks.executor.executor.task.TaskExecutor;
import spring.cloud.tasks.executor.executor.task.TaskListenerHolder;
import spring.cloud.tasks.executor.executor.task.task_item_execute.TaskItemExecuteRenewalInfoService;

@Slf4j
@Setter
@Getter
public class ExecuteStatisticsNeedReportListenerHolder extends TaskListenerHolder {
    public boolean isShutdown = false;

    public TaskItemExecuteRenewalInfoService taskItemExecuteInfoService;

    public ExecuteStatisticsNeedReportListenerHolder(TaskExecutor taskExecutor) {
        super(taskExecutor);
        taskItemExecuteInfoService = taskExecutor.getTaskItemExecuteInfoService();
    }

    @Override
    public void start() {
        taskExecutorNodeCacheOrTreeCacheManager.addTreeCacheListener(TaskNodePaths.getTaskNodePath(taskId, ExecuteStatisticsNeedReportNode.NEED_REPORT_NODE), 0, new ExecuteStatisticsNeedReportListener(this));
    }

    @Override
    public void stop() {
        super.stop();
        isShutdown = true;
        taskExecutorNodeCacheOrTreeCacheManager.closeTreeCache(TaskNodePaths.getTaskNodePath(taskId, ExecuteStatisticsNeedReportNode.NEED_REPORT_NODE), 0);
    }

}
